<!--
 * @Description:
 * @Author bianpengfei
 * @create 2022/11/8 22:17
 -->
<template>
  <el-dialog
    v-if="_visible"
    :visible.sync="_visible"
    append-to-body
    width="1150px"
    :title="_title"
    top="50px"
    :close-on-click-modal="false"
  >
    <template v-if="model == 1">
      <!-- 新增     -->
      <el-form :model="form" label-width="100px">
        <el-form-item
          prop="title"
          label="公告标题"
          :rules="[{ required: true, message: '请输入公告标题', trigger: 'blur' }]"
        >
          <el-input v-model="form.title" placeholder="请输入公告标题" clearable></el-input>
        </el-form-item>

        <el-form-item
          prop="content"
          label="内容"
          :rules="[{ required: true, message: '请输入公告标题', trigger: 'blur' }]"
        >
          <g-tinymce v-model="form.content"></g-tinymce>
        </el-form-item>
      </el-form>

      <div class="items-center flex justify-center pb-12px">
        <el-button type="primary">保存</el-button>
        <el-button @click="onReset">重置</el-button>
      </div>
    </template>

    <template v-else-if="model == 2">
      <!-- 新增     -->
    </template>
  </el-dialog>
</template>

<script>
export default {
  props: {
    visible: {
      type: Boolean,
      default: false
    },

    model: {
      type: [String, Number],
      default: 1 // 1 新增 2 编辑
    }
  },

  data() {
    return {
      form: {
        title: '',
        content: ''
      }
    }
  },

  computed: {
    _title() {
      const conf = {
        1: '新增公告信息',
        2: '编辑公告信息'
      }
      return conf[String(this.model)]
    },

    _visible: {
      get() {
        return this.visible
      },
      set(val) {
        this.$emit('update:visible', val)
      }
    }
  },

  watch: {},

  created() {},

  mounted() {
    this.$once('hook:beforeDestroy', () => {
      // this.removeEvents()
    })
  },

  methods: {
    onReset() {
      this.form = {
        ...this.form,
        title: '',
        content: ''
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.page {
}
</style>
